import request from '@/utils/request'

// 用户信息接口
export interface UserInfo {
  id: number
  email: string
  nickname: string
  avatar: string
  storageQuota: number
  usedStorage: number
  emailVerified: number
  memberType: number
  status: number
  createTime: string
  updateTime: string
  role: number
}

// 登录参数
export interface LoginParams {
  email: string
  password: string
}

// 注册参数
export interface RegisterParams {
  email: string
  password: string
  nickname?: string
  verifyCode: string
}

// 发送验证码参数
export interface SendVerifyCodeParams {
  email: string
  type: 'register' | 'reset'
}

// 更新用户信息参数
export interface UpdateUserParams {
  nickname?: string
  avatar?: string
}

// 修改密码参数
export interface ChangePasswordParams {
  oldPassword: string
  newPassword: string
}

// 登录响应
export interface LoginResponse {
  token: string
  user: UserInfo
}

// 用户登录
export const login = (params: LoginParams): Promise<LoginResponse> => {
  return request.post('/user/login', params)
}

// 用户注册
export const register = (params: RegisterParams): Promise<UserInfo> => {
  return request.post('/user/register', params)
}

// 发送验证码
export const sendVerifyCode = (params: SendVerifyCodeParams): Promise<void> => {
  return request.post('/user/send-verify-code', params)
}

// 获取用户信息
export const getUserInfo = (): Promise<UserInfo> => {
  return request.get('/user/info')
}

// 更新用户信息
export const updateUserInfo = (params: UpdateUserParams): Promise<UserInfo> => {
  return request.post('/user/update', null, { params })
}

// 修改密码
export const changePassword = (params: ChangePasswordParams): Promise<void> => {
  return request.post('/user/change-password', params)
}